package com.lqq.view;

import com.lqq.componment.HBox;
import com.lqq.componment.JDateChooser;
import com.lqq.util.ComBoxUtil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Application {
    public static void show(){
        JFrame jf=new JFrame();
        jf.setVisible(true);
        jf.setSize(700,500);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.setTitle("预约申请");
        jf.setLocationRelativeTo(null);

        JPanel panel=new JPanel(null);
        Box box=Box.createVerticalBox();
        box.setBounds(150,4,400,426);

        JLabel lab1=new JLabel("预        约");
        JLabel lab2=new JLabel("所属学院");
        JLabel lab3=new JLabel("开始时间");
        JLabel lab4=new JLabel("结束时间");
        JLabel lab5=new JLabel("业务选择");
        JLabel lab6=new JLabel("区域选择");
        JLabel lab7=new JLabel("房间选择");
        JLabel lab8=new JLabel("申请理由");

        JTextField text1=new JTextField(16);
        JTextField text2=new JTextField(16);

        final String[] sDate = {""};
        final String[] eDate = {""};

        Button startDate=new Button("startDate");
        startDate.setSize(100,80);
        startDate.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                sDate[0] = JDateChooser.getDate1();
            }
        });
        Button endDate=new Button("endDate");
        endDate.setSize(100,80);
        endDate.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                eDate[0] =JDateChooser.getDate1();
            }
        });

        String[] serviceSelect=new String[]{"通用预约业务","业务2","业务3","业务4"};
        JComboBox serviceComBox= ComBoxUtil.creatComBox(serviceSelect);

        String[] areaSelect=new String[]{"请选择","业务2","业务3","业务4"};
        JComboBox areaComBox=ComBoxUtil.creatComBox(areaSelect);

        String[] roomSelect=new String[]{"请选择","业务2","业务3","业务4"};
        JComboBox roomComBox=ComBoxUtil.creatComBox(roomSelect);

        JTextField text3=new JTextField(25);

        Box box1=HBox.creatHBox(30,lab1,text1);
        Box box2=HBox.creatHBox(30,lab2,text2);
        Box box3=HBox.creatHBox(30,lab3,startDate);
        Box box4=HBox.creatHBox(30,lab4,endDate);
        Box box5=HBox.creatHBox(30,lab5,serviceComBox);
        Box box6=HBox.creatHBox(30,lab6,areaComBox);
        Box box7=HBox.creatHBox(30,lab7,roomComBox);
        Box box8=HBox.creatHBox(30,lab8,text3);

        box.add(Box.createVerticalStrut(30));
        box.add(box1);
        box.add(Box.createVerticalStrut(30));
        box.add(box2);
        box.add(Box.createVerticalStrut(30));
        box.add(box3);
        box.add(Box.createVerticalStrut(30));
        box.add(box4);
        box.add(Box.createVerticalStrut(30));
        box.add(box5);
        box.add(Box.createVerticalStrut(30));
        box.add(box6);
        box.add(Box.createVerticalStrut(30));
        box.add(box7);
        box.add(Box.createVerticalStrut(30));
        box.add(box8);

        panel.add(box);


        JButton btn=new JButton("查询");
        btn.setBounds(590,150,60,108);
        //添加监听器
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println(text1.getText());
                System.out.println(text2.getText());
                System.out.println(text3.getText());
                System.out.println("startDate="+sDate[0]);
                System.out.println("endDate="+eDate[0]);
            }
        });
        panel.add(btn);

        jf.setContentPane(panel);
        jf.revalidate();
    }
}
